/* 
 * File:   Shape.h
 * Author: brady
 *
 * Created on February 2, 2011, 7:05 PM
 */


#include "Ray.h"
#include "BoundingBox.h"
#include <math.h>
#include <float.h>
#include <algorithm>

class Shader;

using namespace cs5721;

#ifndef SHAPE_H
#define	SHAPE_H


class HitStruct;
class Shape {
public:

    
    static const int X_VAL = 0;
    static const int Y_VAL = 1;
    static const int Z_VAL = 2;
    Shape();
    virtual ~Shape();
    virtual bool TestIntersect(Ray &ray, double tmin, double tmax, HitStruct& hitStruct) = 0;
    virtual double GetSortValue(int sortBy)=0;
    virtual void SetShader(Shader* shader) = 0;
    virtual Shader* GetShader()= 0;
    Vector3D Origin;
    BoundingBox* GetBoundingBox(){return boundingBox;}
    string type;
    string InstanceId;
protected:
    double tval;
    bool wasHit;
    Shader* shader;
    Shape* hitShape;
    BoundingBox* boundingBox;
private:

};

class ShapeComparitor{
public:
    ShapeComparitor(int sortAxis)
    {
        this->sortAxis = sortAxis;
    }

    bool operator() (Shape* s1, Shape* s2)
    {
        double s1Val = s1->GetSortValue(sortAxis);
        double s2Val = s2->GetSortValue(sortAxis);
       return (s1Val < s2Val);
    }
    int sortAxis;
};

class HitStruct
{
public:
    Shader* shader;
    double tVal;
    Vector3D normal;
    HitStruct(){shader = NULL; tVal = DBL_MAX; normal = Vector3D(1.0, 1.0, 1.0);}
    HitStruct(Shader* s, int t, Vector3D& n)
    {
        normal = n;
        shader = s;
        tVal = t;
    }

};


#endif	/* SHAPE_H */

